using System;
using UnityEngine;
using UnityEngine.UI;

public class ColorButton : MonoBehaviour
{
	[SerializeField]
	private Image m_ButtonImage;

	[SerializeField]
	private Shadow m_ButtonShadowImage;

	private Button m_Button;

	public Color Color => m_ButtonImage.color;

	public static event Action<Color> OnColorButtonClicked;

	private void Awake()
	{
		m_Button = GetComponentInChildren<Button>();
	}

	public void Init(Color _Color)
	{
		m_Button.onClick.AddListener(OnClick);
		m_ButtonImage.color = _Color;
		Color.RGBToHSV(_Color, out var H, out var S, out var V);
		m_ButtonShadowImage.effectColor = Color.HSVToRGB(H, S, V);
	}

	private void OnClick()
	{
		ColorButton.OnColorButtonClicked?.Invoke(Color);
	}
}
